home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************/
- /* */
- /* Program Name: Stiletto */
- /* */
- /* File Name: DNWindow.c */
- /* */
- /* © Apple Computer, Inc. 1991-1995 */
- /* All Rights Reserved */
- /* */
- /* Revision History: */
- /* */
- /* Date Who Modification */
- /* */
- /* 1991-07-05 Chris Halim Original version */
- /* 1995-06-26 Jaakko Railo Version 2.0 */
- /* */
- /************************************************************************************************/
-
- /****************************************** DESCRIPTION ******************************************
-
- *************************************************************************************************/
-
- /******************************************** HEADERS *******************************************/
-
- #include "Resources.h"
- #include "stdio.h"
- #include "ToolUtils.h"
-
- #ifndef __TELEPHONES__
- #include "Telephones.h"
- #endif
-
- #include "CAHandlers.h"
- #include "Constants.h"
- #include "DNHandlers.h"
- #include "DNWindow.h"
- #include "LogWindow.h"
- #include "TermWindow.h"
- #include "Utilities.h"
-
- /****************************************** DEFINITIONS *****************************************/
-
- /****************************************** PROTOTYPES ******************************************/
-
- void AttachDNWindowControls (DNWindowPtr dnWindow, TELDNHandle dnHand);
- Boolean DoDNWindowMouseDown (const EventRecord *theEvent);
- void DoDNWindowActivate (WindowPtr theWindow, Boolean becomingActive);
- void DoDNWindowUpdate (WindowPtr theWindow);
- void DoDNWindowClick (WindowPtr theWindow, const EventRecord * theEvent);
- void DoDNWindowOSEvent (const EventRecord *theEvent);
- void DoDNWindowSuspend (Boolean doClipConvert);
- void DoDNWindowResume (Boolean doClipConvert);
-
- OSErr CreateCAList (DNWindowPtr dnWindow);
- void DisposeCAList (DNWindowPtr dnWindow);
- OSErr DummyCreateCAWindowList (DNWindowPtr dnWindow);
- OSErr CreateCAWindowList (DNWindowPtr dnWindow);
-
- void DisplaySelectedCAs (DNWindowPtr dnWindow);
- void DumpSelectedCAInfo (DNWindowPtr dnWindow);
- void DumpSelectedCAState (DNWindowPtr dnWindow);
- void ShowCAWindow (DNWindowPtr dnWindow, short whichCA);
-
- void PrepareForwardDLOGUserItems (DialogPtr theDialog);
- pascal Boolean ForwardDLOGFilterProc (DialogPtr theDialog, EventRecord * theEvent, short *itemHit);
- short DisplayForwardDialog (DNWindowPtr dnWindow);
- void PutForwardAttribToDialog (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib);
- void PutDialogSetupToForwardAttrib (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib);
-
- OSErr SetForwarding (DNWindowPtr dnWindow);
- OSErr CancelForwarding (DNWindowPtr dnWindow);
- void HandleForward (DNWindowPtr theWindow, short * value);
-
- TELCAHandle GetAvailableCA (void);
-
- short GetANumber (void);
-
- void HandleMakeACall (DNWindowPtr theWindow);
- void HandleIntercom (DNWindowPtr theWindow, short modifiers);
- void HandlePaging (DNWindowPtr theWindow, short modifiers);
- void HandleCallPickup (DNWindowPtr theWindow, short modifiers);
- void HandleVoiceMail (DNWindowPtr theWindow, short modifiers);
- void HandleRetrievePark (DNWindowPtr theWindow, short modifiers);
- void HandleCallBackNow (DNWindowPtr theWindow, short modifiers);
-
- void HandleDND (DNWindowPtr dnWindow, short * value);
- void PrepareDNDDLOGUserItems (DialogPtr theDialog);
- short DisplayDNDDialog (DNWindowPtr dnWindow);
- void PutDNDAttribToDialog (DialogPtr theDialog, DNDAttribHandle theDNDAttrib);
- void PutDialogSetupToDNDAttrib (DialogPtr theDialog, DNDAttribHandle theDNDAttrib);
- OSErr SetDND (DNWindowPtr dnWindow);
- OSErr CancelDND (DNWindowPtr dnWindow);
-
- void PrepareCallPickupDLOGUserItems (DialogPtr theDialog);
- short DisplayCallPickupDialog (DNWindowPtr dnWindow);
- void PutCallPickupAttribToDialog (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib);
- void PutDialogSetupToCallPickupAttrib (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib);
-
- void PrepareMakeACallDLOGUserItems (DialogPtr theDialog);
- short DisplayMakeACallDialog (DNWindowPtr dnWindow);
- void PutMakeACallAttribToDialog (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib);
- void PutDialogSetupToMakeACallAttrib (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib);
-
- void PrepareGetParkIDDLOGUserItems (DialogPtr theDialog);
- short DisplayGetParkIDDialog (Str255 parkID);
-
- short SearchCAList (DNWindowPtr dnWindow, TELCAHandle caHand);
-
- short GetCAIndex (DNWindowPtr dnWindow, TELCAHandle caHand);
-
- /******************************************** GLOBALS *******************************************/
-
- extern LogWindowPtr gLogWindow;
- extern TelWindowPtr gTelWindow;
-
- extern TELCAHandle gAvailableCA;
-
- extern TelephoneDNMsgUPP gDNMsgHandlerUPP;
- extern TelephoneCAMsgUPP gCAMsgHandlerUPP;
- extern TelephoneCAMsgUPP gCAActiveMsgHandlerUPP;
- extern ModalFilterUPP gStandardFilterUPP;
- extern UserItemUPP gDrawBoxUPP;
- extern UserItemUPP gDrawDefaultUPP;
-
- /************************************************************************************************/
- /************************************************************************************************/
-
-
- #pragma segment DNWindow
- Boolean IsHandledByDNWindowList (DNWindowPtr dnWindowList, const EventRecord * theEvent)
- {
- Boolean wasHandled = false;
- DNWindowPtr tDNWindow = dnWindowList;
-
- while (tDNWindow && !(wasHandled = IsHandledByDNWindow (tDNWindow, theEvent))) {
- tDNWindow = tDNWindow->next;
- }
-
- return (wasHandled);
- }
-
-
- Boolean IsHandledByDNWindow (DNWindowPtr dnWindow, const EventRecord * theEvent)
- {
- WindowPtr theWindow;
- Boolean wasHandled = false;
- char key;
- OSErr errCode;
-
- if (dnWindow != nil) {
- if ((wasHandled = IsHandledByCAWindowList (dnWindow->fCAWindowList, theEvent)) == false) {
-
- switch ( theEvent->what ) {
- case mouseDown:
- (void) FindWindow(theEvent->where, &theWindow);
- if (theWindow == (WindowPtr) dnWindow) {
- wasHandled = DoDNWindowMouseDown (theEvent);
- }
- break;
-
- case activateEvt:
- if ((DNWindowPtr) theEvent->message == dnWindow) {
- DoDNWindowActivate ((WindowPtr) dnWindow, (theEvent->modifiers & activeFlag) != 0);
- wasHandled = true;
- }
- break;
-
- case updateEvt:
- if ((DNWindowPtr) theEvent->message == dnWindow) {
- DoDNWindowUpdate ((WindowPtr) dnWindow);
- wasHandled = true;
- }
- break;
-
- case osEvt:
- if ((DNWindowPtr) FrontWindow () == dnWindow) {
- DoDNWindowOSEvent (theEvent);
- wasHandled = false;
- }
- break;
-
- case keyDown:
- case autoKey:
- if ((DNWindowPtr) FrontWindow() == dnWindow) {
- key = theEvent->message & charCodeMask;
- if ( theEvent->modifiers & cmdKey ) { // Command key is down
- wasHandled = false;
- } else {
- switch (key) {
- case leftArrowKey :
- case upArrowKey :
- SelectPreviousCell (dnWindow->fCAList);
- wasHandled = true;
- break;
-
- case rightArrowKey :
- case downArrowKey :
- SelectNextCell (dnWindow->fCAList);
- wasHandled = true;
- break;
-
- case crKey :
- case enterKey :
- DisplaySelectedCAs (dnWindow);
- wasHandled = true;
- break;
-
- case 'c' :
- case 'C' :
- DumpSelectedCAInfo (dnWindow);
- wasHandled = true;
- break;
-
- case 's' :
- DumpSelectedCAState (dnWindow);
- wasHandled = true;
- break;
-
- case 'm' :
- errCode = TELCAMsgHand (dnWindow->fDNHandle, telCAActiveMsg, gCAActiveMsgHandlerUPP, SetCurrentA5());
- if (errCode == noErr)
- PutLine (gLogWindow, "gCAActiveMsgHandlerUPP is installed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELCAMsgHand fails : %d", errCode);
- break;
-
- case 'M' :
- errCode = TELClrCAMsgHand (dnWindow->fDNHandle, gCAActiveMsgHandlerUPP);
- if (errCode == noErr)
- PutLine (gLogWindow, "gCAActiveMsgHandlerUPP is removed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELClrCAMsgHand fails : %d", errCode);
- break;
-
- case 'f' :
- case 'F' :
- DumpDNFlags (dnWindow->fDNHandle);
- break;
-
- case 'i' :
- case 'I' :
- DumpDNInfo (dnWindow->fDNHandle);
- break;
-
- case 'e' :
- case 'E' :
- DumpDNEvents (dnWindow->fDNHandle);
- break;
-
- default :
- wasHandled = false;
- }
- }
- }
- break;
-
- default :
- wasHandled = false;
- }
- }
- }
-
- return (wasHandled);
- }
-
-
- void DisposeCAList (DNWindowPtr dnWindow)
- {
- /**
- ** Will dispose the list pointed to by fCAList & fCAWindowList
- ** if they are not nil
- **
- **/
-
- CAWindowPtr tCAWindow1, tCAWindow2;
-
- if (dnWindow->fCAList != nil)
- {
- LDispose (dnWindow->fCAList);
- dnWindow->fCAList = nil;
-
- tCAWindow1 = dnWindow->fCAWindowList;
- while (tCAWindow1 != nil)
- {
- tCAWindow2 = tCAWindow1;
- tCAWindow1 = tCAWindow1->next;
- DisposeCAWindow (tCAWindow2);
- }
-
- dnWindow->fCAWindowList = nil;
- }
- }
-
-
- Boolean DoDNWindowMouseDown (const EventRecord *theEvent)
- {
- short part;
- WindowPtr theWindow;
- Boolean wasHandled = false;
-
- part = FindWindow(theEvent->where, &theWindow);
- switch ( part ) {
- case inContent:
- if ( theWindow != FrontWindow() ) {
- SelectWindow(theWindow);
- } else
- DoDNWindowClick (theWindow, theEvent);
-
- wasHandled = true;
- break;
-
- default :
- wasHandled = false;
- }
-
- return (wasHandled);
- }
-
-
- void DoDNWindowOSEvent (const EventRecord *theEvent)
- {
- Boolean doConvert;
- unsigned char evType;
-
- evType = (unsigned char) (theEvent->message >> 24) & 0x00ff; // Get the high byte.
- switch (evType) { // The high byte of message is the type of event.
- case suspendResumeMessage :
- doConvert = (theEvent->message & convertClipboardFlag) != 0;
-
- if ((theEvent->message & resumeFlag) == 0)
- DoDNWindowSuspend (doConvert);
-
- else DoDNWindowResume (doConvert);
- break;
- }
- }
-
-
- void DoDNWindowSuspend (Boolean doClipConvert)
- {
- #pragma unused (doClipConvert)
-
- DoDNWindowActivate (FrontWindow(), false);
- }
-
-
- void DoDNWindowResume (Boolean doClipConvert)
- {
- #pragma unused (doClipConvert)
-
- InitCursor ();
- DoDNWindowActivate (FrontWindow(), true);
- }
-
-
- void DisplaySelectedCAs (DNWindowPtr dnWindow)
- {
- Cell tCell;
-
- SetPt (&tCell, 0, 0);
- while (LGetSelect (true, &tCell, dnWindow->fCAList)) {
- ShowCAWindow (dnWindow, tCell.v);
- if (! LNextCell (true, true, &tCell, dnWindow->fCAList))
- break;
- }
- }
-
-
- void DoDNWindowClick (WindowPtr theWindow, const EventRecord * theEvent)
- {
- Point mousePos;
- WindowPtr savedPort;
- short part, value;
- Boolean dblClicked;
- ControlHandle theControl;
-
- GetPort (&savedPort);
- SetPort (theWindow);
-
- mousePos = theEvent->where;
- GlobalToLocal (&mousePos);
-
- if (((DNWindowPtr) theWindow)->fCAList != nil) {
- dblClicked = LClick (mousePos, theEvent->modifiers, ((DNWindowPtr) theWindow)->fCAList);
-
- if (dblClicked == true) {
- DisplaySelectedCAs ((DNWindowPtr) theWindow);
- }
- }
-
- part = FindControl (mousePos, theWindow, &theControl);
- switch (part) {
- case 0 : // invisible or inactive control was clicked
- break;
-
- case inThumb :
- break;
-
- case inButton :
- part = TrackControl (theControl, mousePos, nil);
- if (part != 0) {
- switch (GetCRefCon (theControl)) {
- case rMakeACallCNTL :
- HandleMakeACall ((DNWindowPtr) theWindow);
- break;
-
- case rIntercomCNTL :
- HandleIntercom ((DNWindowPtr) theWindow, theEvent->modifiers);
- break;
-
- case rPagingCNTL :
- HandlePaging ((DNWindowPtr) theWindow, theEvent->modifiers);
- break;
-
- case rCallPickupCNTL :
- HandleCallPickup ((DNWindowPtr) theWindow, theEvent->modifiers);
- break;
-
- case rVoiceMailCNTL :
- HandleVoiceMail ((DNWindowPtr) theWindow, theEvent->modifiers);
- break;
-
- case rRetrieveParkCNTL :
- HandleRetrievePark ((DNWindowPtr) theWindow, theEvent->modifiers);
- break;
-
- case rCallBackNowCNTL :
- HandleCallBackNow ((DNWindowPtr) theWindow, theEvent->modifiers);
- break;
- }
- }
- break;
-
- case inCheckBox:
- part = TrackControl (theControl, mousePos, nil);
- if (part != 0) {
- value = (GetCtlValue (theControl)) ? false : true;
-
- switch (GetCRefCon (theControl)) {
- case rForwardCNTL :
- HandleForward ((DNWindowPtr) theWindow, &value);
- break;
-
- case rDNDCNTL :
- HandleDND ((DNWindowPtr) theWindow, &value);
- break;
- }
-
- SetCtlValue (theControl, value);
- }
- break;
- }
-
- SetPort (savedPort);
- }
-
-
- void DoDNWindowActivate (WindowPtr theWindow, Boolean becomingActive)
- {
- WindowPtr savedPort;
- ControlHandle theControl;
-
- GetPort (&savedPort);
- SetPort (theWindow);
-
- theControl = ((WindowPeek) theWindow)->controlList;
- while (theControl != nil) {
- HiliteControl (theControl, (becomingActive)?0:255);
- theControl = (*theControl)->nextControl;
- }
-
- if (((DNWindowPtr) theWindow)->fCAList != nil)
- LActivate (becomingActive, ((DNWindowPtr) theWindow)->fCAList);
-
- SetPort (savedPort);
- }
-
-
- void DoDNWindowUpdate (WindowPtr theWindow)
- {
- WindowPtr savedPort;
- Rect tRect;
-
- BeginUpdate (theWindow);
- if ( ! EmptyRgn (theWindow->visRgn) )
- {
- GetPort (&savedPort);
- SetPort (theWindow);
-
- // EraseRect(&theWindow->portRect);
- UpdtControl (theWindow, theWindow->visRgn);
-
- if (((DNWindowPtr) theWindow)->fCAList != nil) {
- LUpdate (theWindow->visRgn, ((DNWindowPtr) theWindow)->fCAList);
-
- tRect = (*((DNWindowPtr) theWindow)->fCAList)->rView;
- InsetRect (&tRect, -1, -1);
- FrameRect (&tRect);
- }
- SetPort (savedPort);
- }
- EndUpdate (theWindow);
- }
-
-
- OSErr CreateCAList (DNWindowPtr dnWindow)
- {
- /**
- ** This routine will create a list of CAs using the list manager.
- ** If successful, it will call CreateCAWindowList to build the
- ** list of CA windows.
- **
- **/
-
- Rect rView, dataBounds;
- Point cSize;
- Rect **rectHandle;
- WindowPtr savedPort;
-
- SetRect (&dataBounds, 0, 0, 1, 0); // one-column list
-
- SetPt (&cSize, 0, 0); // use default cell size
-
- rectHandle = (Rect **) Get1Resource ('RECT', rCAListRECT);
- if (rectHandle) {
- rView = **rectHandle;
- rView.right -= 15;
- ReleaseResource ((Handle) rectHandle);
- } else {
- rView = ((WindowPtr) dnWindow)->portRect;
- rView.right -= 15;
- }
-
- if ((dnWindow->fCAList = lnew (&rView, &dataBounds, &cSize, 0, (WindowPtr)dnWindow,
- true, false, false, true)) != nil) {
-
- LActivate (false, dnWindow->fCAList);
-
- GetPort (&savedPort);
- SetPort ((WindowPtr) dnWindow);
- InvalRect (&rView);
- SetPort (savedPort);
-
- #ifdef DEBUGNOCARD
- return (DummyCreateCAWindowList (dnWindow));
- #else
- return (CreateCAWindowList (dnWindow));
- #endif /* DEBUGNOCARD */
- }
- else
- return (MemError());
- }
-
-
- #ifdef DEBUGNOCARD
- OSErr DummyCreateCAWindowList (DNWindowPtr dnWindow)
- {
- OSErr errCode = noErr;
- short numOfCAs, index;
- TELCAHandle caHand = nil;
- CAWindowPtr *tCAWindow;
- Cell tCell;
- char *ca[1];
-
- ca[0] = "ca#1";
-
- tCAWindow = &dnWindow->fCAWindowList;
-
- numOfCAs = 1;
-
- for (index = 1; index <= numOfCAs; ++index) {
- *tCAWindow = CreateCAWindow (caHand, ca[index-1]);
- (*caHand)->refCon = (long) dnWindow;
- if (*tCAWindow != nil) {
- tCAWindow = &(*tCAWindow)->next;
-
- SetPt (&tCell, 0, index-1);
- LAddRow (1, index-1, dnWindow->fCAList);
- LSetCell (ca[index-1], 4, tCell, dnWindow->fCAList);
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### CreateCAWindow fails");
- }
-
- if (numOfCAs > 0) { // hilite the first row & column
- SetPt (&tCell, 0, 0);
- LSetSelect (true, tCell, dnWindow->fCAList);
- }
-
- return (errCode);
- }
- #endif /* DEBUGNOCARD */
-
-
- OSErr CreateCAWindowList (DNWindowPtr dnWindow)
- {
- OSErr errCode;
- short numOfCAs = 0, index;
- TELDNHandle dnHand;
- TELCAHandle caHand;
- CAWindowPtr *tCAWindow;
- Cell tCell;
- Str31 title;
-
- dnHand = dnWindow->fDNHandle;
- tCAWindow = &dnWindow->fCAWindowList;
-
- if (dnHand != nil) {
-
- (void) TELGetDNInfo (dnHand);
-
- numOfCAs = TELCountCAs (dnHand, telAllCallOrigins);
-
- for (index = 1; index <= numOfCAs; ++index) {
- errCode = TELCALookup (dnHand, telAllCallOrigins, index, &caHand);
- if (errCode == noErr) {
- sprintf ((char *) title, "caHand = 0x%x", caHand);
- *tCAWindow = CreateCAWindow (caHand, (char *) title);
- (*caHand)->refCon = (long) dnWindow;
- if (*tCAWindow != nil) {
- tCAWindow = &(*tCAWindow)->next;
-
- SetPt (&tCell, 0, index-1);
- LAddRow (1, index-1, dnWindow->fCAList);
-
- UpdateCAListState (dnWindow, caHand);
- }
- else
- if ((errCode = TELCADispose (caHand)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELCADispose failed : %d", errCode);
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### TELCALookup fails : %d", errCode);
- }
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### Invalid dnHand");
-
- if (numOfCAs > 0) { // hilite the first row & column
- SetPt (&tCell, 0, 0);
- LSetSelect (true, tCell, dnWindow->fCAList);
- }
-
- return (errCode);
- }
-
-
- DNWindowPtr CreateDNWindow (TELDNHandle dnHand, char * title)
- {
- DNWindowPtr dnWindow;
- WindowPtr savedPort;
- Ptr tPtr;
-
- tPtr = NewPtrClear (sizeof (DNWindowRec));
- if (tPtr == nil) {
- AlertUser ("\pNot enough memory to create dn window !", MemError ());
- return (nil);
- }
-
- if (HasColorQD ())
- dnWindow = (DNWindowPtr) GetNewCWindow (rDNWIND, tPtr, (WindowPtr)(-1L));
- else
- dnWindow = (DNWindowPtr) GetNewWindow (rDNWIND, tPtr, (WindowPtr)(-1L));
-
- if (dnWindow == nil) {
- AlertUser ("\pUnable to get a WIND resource for dn window!", ResError ());
- DisposPtr (tPtr);
- return (nil);
- }
-
- dnWindow->fForwardAttrib = (ForwardAttribHandle) NewHandleClear (sizeof(ForwardAttrib));
- if (dnWindow->fForwardAttrib == nil) {
- AlertUser ("\pNot enough memory to create dn window !", MemError ());
- DisposeWindow ((WindowPtr) dnWindow);
- return (nil);
- }
- (*dnWindow->fForwardAttrib)->fwdType = telForwardImmediate;
-
- dnWindow->fDNDAttrib = (DNDAttribHandle) NewHandleClear (sizeof(DNDAttrib));
- if (dnWindow->fDNDAttrib == nil) {
- AlertUser ("\pNot enough memory to create dn window !", MemError ());
- DisposeWindow ((WindowPtr) dnWindow);
- return (nil);
- }
-
- dnWindow->fCallPickupAttrib = (CallPickupAttribHandle) NewHandleClear (sizeof(CallPickupAttrib));
- if (dnWindow->fCallPickupAttrib == nil) {
- AlertUser ("\pNot enough memory to create dn window !", MemError ());
- DisposeWindow ((WindowPtr) dnWindow);
- return (nil);
- }
-
- dnWindow->fMakeACallAttrib = (MakeACallAttribHandle) NewHandleClear (sizeof(MakeACallAttrib));
- if (dnWindow->fMakeACallAttrib == nil) {
- AlertUser ("\pNot enough memory to create dn window !", MemError ());
- DisposeWindow ((WindowPtr) dnWindow);
- return (nil);
- }
-
- /**
- ** Set the window's characteristics.
- **
- **/
-
- GetPort (&savedPort);
- SetPort ((WindowPtr) dnWindow);
- TextSize (9);
- SetPort (savedPort);
-
- setwtitle ((WindowPtr) dnWindow, title);
-
- AttachDNWindowControls (dnWindow, dnHand);
-
- dnWindow->fDNHandle = dnHand;
- (void) InstallDNHandler (dnHand);
- (void) InstallCAHandler (dnHand);
-
- if (CreateCAList (dnWindow) == nil) {}
-
- (*dnHand)->userData = (long) dnWindow; // so we can find the corresponding dnwindow if given a dnHand
-
- ShowWindow ((WindowPtr) dnWindow);
-
- return (dnWindow);
- }
-
-
- void DisposeDNWindow (DNWindowPtr dnWindow)
- {
- OSErr errCode;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- CAWindowPtr caWindow, tCAWindow;
-
- if (dnWindow != nil) {
- if (dnWindow->fCAList != nil)
- LDispose (dnWindow->fCAList);
-
- caWindow = dnWindow->fCAWindowList;
- while (tCAWindow = caWindow) {
- caWindow = caWindow->next;
- DisposeCAWindow (tCAWindow);
- }
-
- if (dnWindow->fForwardAttrib)
- DisposHandle ((Handle) dnWindow->fForwardAttrib);
- if (dnWindow->fDNDAttrib)
- DisposHandle ((Handle) dnWindow->fDNDAttrib);
- if (dnWindow->fCallPickupAttrib)
- DisposHandle ((Handle) dnWindow->fCallPickupAttrib);
- if (dnWindow->fMakeACallAttrib)
- DisposHandle ((Handle) dnWindow->fMakeACallAttrib);
-
- if (dnHand) {
- if ((errCode = TELClrDNMsgHand (dnHand, gDNMsgHandlerUPP)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELClrDNMsgHand fails : %d", errCode);
-
- if ((errCode = TELClrCAMsgHand (dnHand, gCAMsgHandlerUPP)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELClrCAMsgHand fails : %d", errCode);
-
- if ((errCode = TELDNDispose (dnHand)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELDNDispose failed : %d", errCode);
- }
-
- DisposeWindow ((WindowPtr) dnWindow);
- }
- }
-
-
- void AttachDNWindowControls (DNWindowPtr dnWindow, TELDNHandle dnHand)
- {
- Boolean fwdActive;
- long forwardFlags;
- OSErr errCode;
- WindowPtr savedPort;
- ControlHandle theControl;
- // Rect boundsRect;
-
- GetPort (&savedPort);
- SetPort ((WindowPtr) dnWindow);
-
- dnWindow->fMakeACall = GetNewControl (rMakeACallCNTL, (WindowPtr) dnWindow);
- dnWindow->fIntercom = GetNewControl (rIntercomCNTL, (WindowPtr) dnWindow);
- dnWindow->fPaging = GetNewControl (rPagingCNTL, (WindowPtr) dnWindow);
- dnWindow->fCallPickup = GetNewControl (rCallPickupCNTL, (WindowPtr) dnWindow);
- dnWindow->fVoiceMail = GetNewControl (rVoiceMailCNTL, (WindowPtr) dnWindow);
- dnWindow->fRetrievePark = GetNewControl (rRetrieveParkCNTL, (WindowPtr) dnWindow);
- (void) GetNewControl (rCallBackNowCNTL, (WindowPtr) dnWindow);
- dnWindow->fForward = GetNewControl (rForwardCNTL, (WindowPtr) dnWindow);
- dnWindow->fDND = GetNewControl (rDNDCNTL, (WindowPtr) dnWindow);
-
- dnWindow->fDirNumber = GetNewControl (rDirNumberCNTL, (WindowPtr) dnWindow);
-
- if ((errCode = TELGetDNInfo (dnHand)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELDNGetInfo fails : %d", errCode);
-
- SetCtlValue (dnWindow->fDND, ((*dnHand)->featureFlags & dndActive));
-
- forwardFlags = (*dnHand)->forwardFlags;
- fwdActive = (forwardFlags & immediateForwardActive) || (forwardFlags & busyForwardActive) ||
- (forwardFlags & noAnswerForwardActive) || (forwardFlags & busyNAForwardActive);
- SetCtlValue (dnWindow->fForward, fwdActive);
-
- SetControlTitle (dnWindow->fDirNumber, (*dnHand)->dn);
-
- theControl = ((WindowPeek) dnWindow)->controlList;
- while (theControl != nil) {
- HiliteControl (theControl, 0xFF);
- theControl = (*theControl)->nextControl;
- }
-
- SetPort (savedPort);
- }
-
-
- void PrepareForwardDLOGUserItems (DialogPtr theDialog)
- {
- short itemType;
- Handle item;
- Rect box;
- CursHandle watch = GetCursor(watchCursor);
-
- if (watch != nil)
- SetCursor (*watch);
-
- GetDItem (theDialog, kForwardBox1, &itemType, &item, &box);
- SetDItem (theDialog, kForwardBox1, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kForwardBox2, &itemType, &item, &box);
- SetDItem (theDialog, kForwardBox2, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kForwardBox3, &itemType, &item, &box);
- SetDItem (theDialog, kForwardBox3, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kForwardDefault, &itemType, &item, &box);
- SetDItem (theDialog, kForwardDefault, itemType, (Handle) gDrawDefaultUPP, &box);
-
- if (watch != nil)
- ReleaseResource ((Handle) watch);
-
- SetCursor (&qd.arrow);
- }
-
-
- short DisplayForwardDialog (DNWindowPtr dnWindow)
- {
- DialogPtr theDialog;
- short itemHit;
- short returnValue;
- ForwardAttribHandle theForwardAttrib = dnWindow->fForwardAttrib;
-
- theDialog = GetNewDialog (rForwardDLOG, nil, (WindowPtr)(-1L));
- if (theDialog == nil) {
- AlertUser ("\pUnable to get a DLOG resource !", ResError());
- return (-1);
- }
-
- PrepareForwardDLOGUserItems (theDialog);
- PutForwardAttribToDialog (theDialog, theForwardAttrib);
-
- ShowWindow (theDialog);
-
- ModalDialog (gStandardFilterUPP, &itemHit);
-
- HideWindow (theDialog);
-
- switch (itemHit) {
- case ok :
- PutDialogSetupToForwardAttrib (theDialog, theForwardAttrib);
- if ((returnValue = SetForwarding (dnWindow)) == noErr)
- returnValue = ok;
-
- break;
-
- default :
- returnValue = cancel;
- }
-
- DisposDialog (theDialog);
-
- return (returnValue);
- }
-
-
- void PutForwardAttribToDialog (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
- Str255 tStr;
-
- GetDItem (theDialog, kForwardNumber, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (**theForwardAttrib).dn);
- SelIText (theDialog, kForwardNumber, 0, 32767);
-
- GetDItem (theDialog, kForwardName, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (**theForwardAttrib).name);
-
- GetDItem (theDialog, kForwardSubAddr, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (**theForwardAttrib).subAddr);
-
- GetDItem (theDialog, kForwardNumRings, &itemKind, &itemHand, &itemRect);
- NumToString ((**theForwardAttrib).numOfRings, tStr);
- SetIText (itemHand, tStr);
-
- GetDItem (theDialog, kForwardPopup, &itemKind, &itemHand, &itemRect);
- SetCtlValue ((ControlHandle) itemHand, (**theForwardAttrib).fwdType);
- }
-
-
- void PutDialogSetupToForwardAttrib (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
- Str255 tStr;
- long tlong;
-
- GetDItem (theDialog, kForwardNumber, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (**theForwardAttrib).dn);
-
- GetDItem (theDialog, kForwardName, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (**theForwardAttrib).name);
-
- GetDItem (theDialog, kForwardSubAddr, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (**theForwardAttrib).subAddr);
-
- GetDItem (theDialog, kForwardNumRings, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, tStr);
- StringToNum (tStr, &tlong);
- (**theForwardAttrib).numOfRings = tlong;
-
- GetDItem (theDialog, kForwardPopup, &itemKind, &itemHand, &itemRect);
- (**theForwardAttrib).fwdType = GetCtlValue ((ControlHandle) itemHand);
- }
-
-
- OSErr SetForwarding (DNWindowPtr dnWindow)
- {
- OSErr errCode = noErr;
- ForwardAttribHandle tForwardAttrib = dnWindow->fForwardAttrib;
- TELDNHandle dnHand = dnWindow->fDNHandle;
-
- if (dnHand) {
- errCode = TELForwardSet (dnHand, (*tForwardAttrib)->dn,
- (*tForwardAttrib)->name,
- (*tForwardAttrib)->subAddr,
- (*tForwardAttrib)->fwdType, (*tForwardAttrib)->numOfRings);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "Forwarding is set successfully");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELForwardSet fails : %d", errCode);
- }
-
- return (errCode);
- }
-
-
- OSErr CancelForwarding (DNWindowPtr dnWindow)
- {
- OSErr errCode = noErr;
- ForwardAttribHandle tForwardAttrib = dnWindow->fForwardAttrib;
- TELDNHandle dnHand = dnWindow->fDNHandle;
-
- if (dnHand) {
- errCode = TELForwardClear (dnHand, (*tForwardAttrib)->fwdType);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "Forwarding is canceled successfully");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELForwardClear fails : %d", errCode);
- }
-
- return (errCode);
- }
-
-
- void HandleForward (DNWindowPtr dnWindow, short * value)
- {
- if (*value) {
- if (DisplayForwardDialog (dnWindow) == ok)
- *value = true;
- else
- *value = false;
- }
- else
- (void) CancelForwarding (dnWindow);
- }
-
-
- void HandleDND (DNWindowPtr dnWindow, short * value)
- {
- if (*value) {
- if (DisplayDNDDialog (dnWindow) == ok)
- *value = true;
- else
- *value = false;
- }
- else
- (void) CancelDND (dnWindow);
- }
-
-
- void HandleMakeACall (DNWindowPtr dnWindow)
- {
- OSErr errCode;
- TELCAHandle caHand;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- MakeACallAttribHandle tMakeACallAttrib = dnWindow->fMakeACallAttrib;
-
- if (dnHand) {
- if (DisplayMakeACallDialog (dnWindow) == ok) {
- errCode = TELSetupCall (dnHand, &caHand,
- (*tMakeACallAttrib)->destDN,
- (*tMakeACallAttrib)->destName,
- (*tMakeACallAttrib)->subAddr,
- (*tMakeACallAttrib)->userUserInfo,
- (*tMakeACallAttrib)->bearerType,
- (*tMakeACallAttrib)->rate);
- if (errCode == noErr) {
- PutLine (gLogWindow, "TELSetupCall (%08x)", caHand);
-
- AppendCAList (dnWindow, caHand);
-
- errCode = TELConnect (caHand);
- if (errCode != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELConnect fails : %d", errCode);
- else
- PutLine (gLogWindow, "TELConnect (%08x)", caHand);
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### TELSetupCall fails : %d", errCode);
- }
- }
- }
-
-
- TELCAHandle SetUpACall (DNWindowPtr dnWindow)
- {
- OSErr errCode;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- MakeACallAttribHandle tMakeACallAttrib = dnWindow->fMakeACallAttrib;
-
- if (dnHand) {
- if (DisplayMakeACallDialog (dnWindow) == ok) {
- errCode = TELSetupCall (dnHand, &caHand,
- (*tMakeACallAttrib)->destDN,
- (*tMakeACallAttrib)->destName,
- (*tMakeACallAttrib)->subAddr,
- (*tMakeACallAttrib)->userUserInfo,
- (*tMakeACallAttrib)->bearerType,
- (*tMakeACallAttrib)->rate);
- if (errCode == noErr) {
- PutLine (gLogWindow, "TELSetupCall (%08x)", caHand);
- AppendCAList (dnWindow, caHand);
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### TELSetupCall fails : %d", errCode);
- }
- }
-
- return (caHand);
- }
-
-
- short GetANumber (void)
- {
- DialogPtr theDialog;
- short itemHit;
- short returnValue = 0;
- short itemKind;
- Handle itemHand;
- Rect itemRect;
- long tlong;
- Str255 tStr;
-
- theDialog = GetNewDialog (rGetANumberDLOG, nil, (WindowPtr)(-1L));
- if (theDialog == nil) {
- AlertUser ("\pUnable to get a DLOG resource !", ResError());
- return (0);
- }
-
- GetDItem (theDialog, kGetANumberNumber, &itemKind, &itemHand, &itemRect);
- SelIText (theDialog, kGetANumberNumber, 0, 32767);
-
- ShowWindow (theDialog);
-
- ModalDialog (nil, &itemHit);
-
- HideWindow (theDialog);
-
- switch (itemHit) {
- case ok :
- GetDItem (theDialog, kGetANumberNumber, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, tStr);
- StringToNum (tStr, &tlong);
- returnValue = tlong;
- break;
- }
-
- DisposDialog (theDialog);
-
- return (returnValue);
- }
-
-
- TELCAHandle GetAvailableCA (void)
- {
- short state;
- OSErr errCode;
-
- if (gAvailableCA) {
- if ((errCode = TELGetCAState (gAvailableCA, &state)) == noErr) {
- if (state != telCADialToneState)
- gAvailableCA = nil;
- }
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELGetCAState fails : %d", errCode);
- gAvailableCA = nil;
- }
- }
-
- return (gAvailableCA);
- }
-
-
- TELCAHandle GetFreeCAHandle (DNWindowPtr dnWindow, short getNewCA)
- {
- OSErr errCode;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- short bearerType = 0, rate = 0;
-
- if (! getNewCA)
- caHand = GetAvailableCA ();
-
- if (caHand == nil) // either user wants a new ca or the avail ca is not in dialtone state
- if (dnHand) {
- errCode = TELSetupCall (dnHand, &caHand, "\p", "\p", "\p", "\p", bearerType, rate);
-
- if (errCode != noErr) {
- caHand = nil;
- PutCLine (gLogWindow, kErrorColor, "### TELSetupCall fails : %d", errCode);
- }
- else {
- PutLine (gLogWindow, "TELSetupCall (%08x)", caHand);
- AppendCAList (dnWindow, caHand);
- }
- }
-
- return (caHand);
- }
-
-
- void HandleIntercom (DNWindowPtr dnWindow, short modifiers)
- {
- OSErr errCode = noErr;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- short intercomID;
-
- if (dnHand) {
- intercomID = (*dnHand)->numIntercomIDs;
- if (intercomID > 0) {
- PutLine (gLogWindow, "NumIntercomIDs = %d", intercomID);
- intercomID = GetANumber ();
- }
-
- if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
-
- errCode = TELIntercom (caHand, intercomID);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "TELInterCom (%08x)", caHand);
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELIntercom fails : %d", errCode);
-
- RemoveFromCAList (dnWindow, caHand);
- }
- }
- }
- }
-
-
- void HandlePaging (DNWindowPtr dnWindow, short modifiers)
- {
- OSErr errCode = noErr;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- short pageID;
-
- if (dnHand) {
- pageID = (*dnHand)->numPageIDs;
- if (pageID > 0) {
- PutLine (gLogWindow, "NumPageIDs = %d", pageID);
- pageID = GetANumber ();
- }
-
- if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
- errCode = TELPaging (caHand, pageID);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "TELPaging (%08x)", caHand);
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELPaging fails : %d", errCode);
-
- RemoveFromCAList (dnWindow, caHand);
- }
- }
- }
- }
-
-
- void HandleCallPickup (DNWindowPtr dnWindow, short modifiers)
- {
- OSErr errCode = noErr;
- CallPickupAttribHandle tCallPickupAttrib = dnWindow->fCallPickupAttrib;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- short pickupIDs;
-
- if (dnHand) {
- pickupIDs = (*dnHand)->numPickupIDs;
- if (pickupIDs > 0)
- PutLine (gLogWindow, "NumPickupIDs = %d", pickupIDs);
-
- if (DisplayCallPickupDialog (dnWindow) == ok) {
- if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
- errCode = TELCallPickup (caHand, (*tCallPickupAttrib)->pickupDN,
- (*tCallPickupAttrib)->pickupGroupID);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "TELCallPickup is called successfully");
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELCallPickup fails : %d", errCode);
-
- RemoveFromCAList (dnWindow, caHand);
- }
- }
- }
- }
- }
-
-
- void HandleVoiceMail (DNWindowPtr dnWindow, short modifiers)
- {
- OSErr errCode = noErr;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
-
- if (dnHand) {
- if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
- errCode = TELVoiceMailAccess (caHand);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "TELVoiceMailAccess (%08x)", caHand);
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELVoiceMailAccess fails : %d", errCode);
-
- RemoveFromCAList (dnWindow, caHand);
- }
- }
- }
- }
-
-
- void HandleRetrievePark (DNWindowPtr dnWindow, short modifiers)
- {
- OSErr errCode = noErr;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- Str255 parkID;
- long caFeatureFlags, caOtherFeatures;
-
- if (dnHand) {
- if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
- if ((errCode = TELGetCAFlags (caHand, &caFeatureFlags, &caOtherFeatures)) == noErr) {
- if (caOtherFeatures & parkRetrieveWithID)
- if (DisplayGetParkIDDialog (parkID) != ok) {
- RemoveFromCAList (dnWindow, caHand);
- return;
- }
-
- errCode = TELRetrieveParkedCall (caHand, parkID);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "TELRetrieveParkedCall (%08x)", caHand);
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELRetrieveParkedCall fails : %d", errCode);
-
- RemoveFromCAList (dnWindow, caHand);
- }
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### TELGetCAFlags fails : %d", errCode);
- }
- }
- }
-
-
- void HandleCallBackNow (DNWindowPtr dnWindow, short modifiers)
- {
- OSErr errCode = noErr;
- TELCAHandle caHand = nil;
- TELDNHandle dnHand = dnWindow->fDNHandle;
- short cbRef = 0;
-
- if (dnHand) {
- if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
- errCode = TELCallbackNow (caHand, cbRef);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "TELCallbackNow (%08x) -> cbRef = %d", caHand, cbRef);
- else {
- PutCLine (gLogWindow, kErrorColor, "### TELCallbackNow fails : %d", errCode);
-
- RemoveFromCAList (dnWindow, caHand);
- }
- }
- }
- }
-
-
- void PrepareDNDDLOGUserItems (DialogPtr theDialog)
- {
- short itemType;
- Handle item;
- Rect box;
- CursHandle watch = GetCursor(watchCursor);
-
- if (watch != nil)
- SetCursor (*watch);
-
- GetDItem (theDialog, kDNDBox1, &itemType, &item, &box);
- SetDItem (theDialog, kDNDBox1, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kDNDDefault, &itemType, &item, &box);
- SetDItem (theDialog, kDNDDefault, itemType, (Handle) gDrawDefaultUPP, &box);
-
- if (watch != nil)
- ReleaseResource ((Handle) watch);
-
- SetCursor (&qd.arrow);
- }
-
-
- short DisplayDNDDialog (DNWindowPtr dnWindow)
- {
- DialogPtr theDialog;
- short itemHit;
- short returnValue;
- DNDAttribHandle theDNDAttrib = dnWindow->fDNDAttrib;
-
- theDialog = GetNewDialog (rDNDDLOG, nil, (WindowPtr)(-1L));
- if (theDialog == nil) {
- AlertUser ("\pUnable to get a DLOG resource !", ResError());
- return (-1);
- }
-
- PrepareDNDDLOGUserItems (theDialog);
- PutDNDAttribToDialog (theDialog, theDNDAttrib);
-
- ShowWindow (theDialog);
-
- ModalDialog (gStandardFilterUPP, &itemHit);
-
- HideWindow (theDialog);
-
- switch (itemHit) {
- case ok :
- PutDialogSetupToDNDAttrib (theDialog, theDNDAttrib);
- if ((returnValue = SetDND (dnWindow)) == noErr)
- returnValue = ok;
-
- break;
-
- default :
- returnValue = cancel;
- }
-
- DisposDialog (theDialog);
-
- return (returnValue);
- }
-
-
- void PutDNDAttribToDialog (DialogPtr theDialog, DNDAttribHandle theDNDAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
-
- GetDItem (theDialog, kDNDPopup, &itemKind, &itemHand, &itemRect);
- SetCtlValue ((ControlHandle) itemHand, (**theDNDAttrib).dndType + 1); // dndtype starts at 0
- }
-
-
- void PutDialogSetupToDNDAttrib (DialogPtr theDialog, DNDAttribHandle theDNDAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
-
- GetDItem (theDialog, kDNDPopup, &itemKind, &itemHand, &itemRect);
- (**theDNDAttrib).dndType = GetCtlValue ((ControlHandle) itemHand) - 1;
- }
-
-
- OSErr SetDND (DNWindowPtr dnWindow)
- {
- OSErr errCode = noErr;
- DNDAttribHandle tDNDAttrib = dnWindow->fDNDAttrib;
- TELDNHandle dnHand = dnWindow->fDNHandle;
-
- if (dnHand) {
- errCode = TELDNDSet (dnHand, (*tDNDAttrib)->dndType);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "DND is set successfully");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELDNDSet fails : %d", errCode);
- }
-
- return (errCode);
- }
-
-
- OSErr CancelDND (DNWindowPtr dnWindow)
- {
- OSErr errCode = noErr;
- DNDAttribHandle tDNDAttrib = dnWindow->fDNDAttrib;
- TELDNHandle dnHand = dnWindow->fDNHandle;
-
- if (dnHand) {
- errCode = TELDNDClear (dnHand, (*tDNDAttrib)->dndType);
-
- if (errCode == noErr)
- PutLine (gLogWindow, "DND is canceled successfully");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELDNDClear fails : %d", errCode);
- }
-
- return (errCode);
- }
-
-
- void PrepareCallPickupDLOGUserItems (DialogPtr theDialog)
- {
- short itemType;
- Handle item;
- Rect box;
- CursHandle watch = GetCursor(watchCursor);
-
- if (watch != nil)
- SetCursor (*watch);
-
- GetDItem (theDialog, kCallPickupBox1, &itemType, &item, &box);
- SetDItem (theDialog, kCallPickupBox1, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kCallPickupDefault, &itemType, &item, &box);
- SetDItem (theDialog, kCallPickupDefault, itemType, (Handle) gDrawDefaultUPP, &box);
-
- if (watch != nil)
- ReleaseResource ((Handle) watch);
-
- SetCursor (&qd.arrow);
- }
-
-
- short DisplayCallPickupDialog (DNWindowPtr dnWindow)
- {
- DialogPtr theDialog;
- short itemHit;
- short returnValue;
- CallPickupAttribHandle theCallPickupAttrib = dnWindow->fCallPickupAttrib;
-
- theDialog = GetNewDialog (rCallPickupDLOG, nil, (WindowPtr)(-1L));
- if (theDialog == nil) {
- AlertUser ("\pUnable to get a DLOG resource !", ResError());
- return (-1);
- }
-
- PrepareCallPickupDLOGUserItems (theDialog);
- PutCallPickupAttribToDialog (theDialog, theCallPickupAttrib);
-
- ShowWindow (theDialog);
-
- ModalDialog (gStandardFilterUPP, &itemHit);
-
- HideWindow (theDialog);
-
- switch (itemHit) {
- case ok :
- PutDialogSetupToCallPickupAttrib (theDialog, theCallPickupAttrib);
- returnValue = ok;
-
- break;
-
- default :
- returnValue = cancel;
- }
-
- DisposDialog (theDialog);
-
- return (returnValue);
- }
-
-
- void PutCallPickupAttribToDialog (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
-
- GetDItem (theDialog, kCallPickupNumber, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (*theCallPickupAttrib)->pickupDN);
- SelIText (theDialog, kCallPickupNumber, 0, 32767);
- }
-
-
- void PutDialogSetupToCallPickupAttrib (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
-
- GetDItem (theDialog, kCallPickupNumber, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (*theCallPickupAttrib)->pickupDN);
- }
-
-
- void PrepareMakeACallDLOGUserItems (DialogPtr theDialog)
- {
- short itemType;
- Handle item;
- Rect box;
- CursHandle watch = GetCursor(watchCursor);
-
- if (watch != nil)
- SetCursor (*watch);
-
- GetDItem (theDialog, kMakeACallBox1, &itemType, &item, &box);
- SetDItem (theDialog, kMakeACallBox1, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kMakeACallDefault, &itemType, &item, &box);
- SetDItem (theDialog, kMakeACallDefault, itemType, (Handle) gDrawDefaultUPP, &box);
-
- if (watch != nil)
- ReleaseResource ((Handle) watch);
-
- SetCursor (&qd.arrow);
- }
-
-
- short DisplayMakeACallDialog (DNWindowPtr dnWindow)
- {
- DialogPtr theDialog;
- short itemHit;
- short returnValue;
- MakeACallAttribHandle theMakeACallAttrib = dnWindow->fMakeACallAttrib;
-
- theDialog = GetNewDialog (rMakeACallDLOG, nil, (WindowPtr)(-1L));
- if (theDialog == nil) {
- AlertUser ("\pUnable to get a DLOG resource !", ResError());
- return (-1);
- }
-
- PrepareMakeACallDLOGUserItems (theDialog);
- PutMakeACallAttribToDialog (theDialog, theMakeACallAttrib);
-
- ShowWindow (theDialog);
-
- ModalDialog (gStandardFilterUPP, &itemHit);
-
- HideWindow (theDialog);
-
- switch (itemHit) {
- case ok :
- PutDialogSetupToMakeACallAttrib (theDialog, theMakeACallAttrib);
- returnValue = ok;
-
- break;
-
- default :
- returnValue = cancel;
- }
-
- DisposDialog (theDialog);
-
- return (returnValue);
- }
-
-
- void PutMakeACallAttribToDialog (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
- Str255 tStr;
-
- GetDItem (theDialog, kMakeACallNumber, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (*theMakeACallAttrib)->destDN);
- SelIText (theDialog, kMakeACallNumber, 0, 32767);
-
- GetDItem (theDialog, kMakeACallName, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (*theMakeACallAttrib)->destName);
-
- GetDItem (theDialog, kMakeACallSubAddr, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (*theMakeACallAttrib)->subAddr);
-
- GetDItem (theDialog, kMakeACallUserInfo, &itemKind, &itemHand, &itemRect);
- SetIText (itemHand, (*theMakeACallAttrib)->userUserInfo);
-
- GetDItem (theDialog, kMakeACallBearer, &itemKind, &itemHand, &itemRect);
- NumToString ((*theMakeACallAttrib)->bearerType, tStr);
- SetIText (itemHand, tStr);
-
- GetDItem (theDialog, kMakeACallRate, &itemKind, &itemHand, &itemRect);
- NumToString ((*theMakeACallAttrib)->rate, tStr);
- SetIText (itemHand, tStr);
- }
-
-
- void PutDialogSetupToMakeACallAttrib (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib)
- {
- short itemKind;
- Handle itemHand;
- Rect itemRect;
- long tlong;
- Str255 tStr;
-
- GetDItem (theDialog, kMakeACallNumber, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (*theMakeACallAttrib)->destDN);
- GetDItem (theDialog, kMakeACallName, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (*theMakeACallAttrib)->destName);
- GetDItem (theDialog, kMakeACallSubAddr, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (*theMakeACallAttrib)->subAddr);
- GetDItem (theDialog, kMakeACallUserInfo, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, (*theMakeACallAttrib)->userUserInfo);
-
- GetDItem (theDialog, kMakeACallBearer, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, tStr);
- StringToNum (tStr, &tlong);
- (*theMakeACallAttrib)->bearerType = tlong;
-
- GetDItem (theDialog, kMakeACallRate, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, tStr);
- StringToNum (tStr, &tlong);
- (*theMakeACallAttrib)->rate = tlong;
- }
-
-
- void PrepareGetParkIDDLOGUserItems (DialogPtr theDialog)
- {
- short itemType;
- Handle item;
- Rect box;
- CursHandle watch = GetCursor(watchCursor);
-
- if (watch != nil)
- SetCursor (*watch);
-
- GetDItem (theDialog, kGetParkIDBox1, &itemType, &item, &box);
- SetDItem (theDialog, kGetParkIDBox1, itemType, (Handle) gDrawBoxUPP, &box);
-
- GetDItem (theDialog, kGetParkIDDefault, &itemType, &item, &box);
- SetDItem (theDialog, kGetParkIDDefault, itemType, (Handle) gDrawDefaultUPP, &box);
-
- if (watch != nil)
- ReleaseResource ((Handle) watch);
-
- SetCursor (&qd.arrow);
- }
-
-
- short DisplayGetParkIDDialog (Str255 parkID)
- {
- DialogPtr theDialog;
- short itemHit;
- short returnValue;
- short itemKind;
- Handle itemHand;
- Rect itemRect;
-
- theDialog = GetNewDialog (rGetParkIDDLOG, nil, (WindowPtr)(-1L));
- if (theDialog == nil) {
- AlertUser ("\pUnable to get a DLOG resource !", ResError());
- return (-1);
- }
-
- PrepareGetParkIDDLOGUserItems (theDialog);
-
- ShowWindow (theDialog);
-
- ModalDialog (gStandardFilterUPP, &itemHit);
-
- HideWindow (theDialog);
-
- switch (itemHit) {
- case ok :
- GetDItem (theDialog, kGetParkIDNumber, &itemKind, &itemHand, &itemRect);
- GetIText (itemHand, parkID);
- returnValue = ok;
- break;
-
- default :
- returnValue = cancel;
- }
-
- DisposDialog (theDialog);
-
- return (returnValue);
- }
-
-
- void DumpSelectedCAInfo (DNWindowPtr dnWindow)
- {
- short count;
- Cell tCell;
- CAWindowPtr tCAWindow;
-
- SetPt (&tCell, 0, 0);
- while (LGetSelect (true, &tCell, dnWindow->fCAList)) {
- tCAWindow = dnWindow->fCAWindowList;
- count = 0;
- while (count++ < tCell.v)
- tCAWindow = tCAWindow->next;
-
- DumpCAInfo (tCAWindow->fCAHandle);
- if (! LNextCell (true, true, &tCell, dnWindow->fCAList))
- break;
- }
- }
-
-
- void DumpSelectedCAState (DNWindowPtr dnWindow)
- {
- short count;
- Cell tCell;
- CAWindowPtr tCAWindow;
-
- SetPt (&tCell, 0, 0);
- while (LGetSelect (true, &tCell, dnWindow->fCAList)) {
- tCAWindow = dnWindow->fCAWindowList;
- count = 0;
- while (count++ < tCell.v)
- tCAWindow = tCAWindow->next;
-
- DumpCAState (tCAWindow->fCAHandle);
- PutLine (gLogWindow, " caHand = %08x", tCAWindow->fCAHandle);
- if (! LNextCell (true, true, &tCell, dnWindow->fCAList))
- break;
- }
- }
-
-
- void ShowCAWindow (DNWindowPtr dnWindow, short whichCA)
- {
- short count = 0;
- CAWindowPtr tCAWindow = dnWindow->fCAWindowList;
-
- while (count++ < whichCA)
- tCAWindow = tCAWindow->next;
-
- ShowWindow ((WindowPtr) tCAWindow);
- SelectWindow ((WindowPtr) tCAWindow);
- }
-
-
- void AppendCAList (DNWindowPtr dnWindow, TELCAHandle caHand)
- {
- CAWindowPtr *caWindow = &dnWindow->fCAWindowList;
- ListHandle theList = dnWindow->fCAList;
- Cell tCell;
- Str31 title;
- OSErr errCode;
- Str255 tString;
- short len;
-
- while (*caWindow != nil)
- caWindow = &(*caWindow)->next;
-
- sprintf ((char *) title, "caHand = 0x%x", caHand);
- *caWindow = CreateCAWindow (caHand, (char *) title);
- (*caHand)->refCon = (long) dnWindow;
- if (*caWindow != nil) {
- SetPt (&tCell, 0, (*theList)->dataBounds.bottom);
- LAddRow (1, (*theList)->dataBounds.bottom, theList);
-
- len = sprintf ((char *) tString, "%08x", caHand);
- LSetCell (tString, len, tCell, theList);
-
- ClearAllSelectedCells (theList);
- LSetSelect (true, tCell, theList);
- }
- else
- if ((errCode = TELCADispose (caHand)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELCADispose failed : %d", errCode);
- }
-
-
- short SearchCAList (DNWindowPtr dnWindow, TELCAHandle caHand)
- {
- CAWindowPtr caWindow;
- short returnValue = -1;
- short row = 0;
-
- if (dnWindow != nil) {
- caWindow = dnWindow->fCAWindowList;
- while (caWindow != nil) {
- if (caWindow->fCAHandle == caHand) {
- returnValue = row;
- break;
- }
- ++row;
- caWindow = caWindow->next;
- }
- }
-
- return (returnValue);
- }
-
-
- void RemoveFromCAList (DNWindowPtr dnWindow, TELCAHandle caHand)
- {
- CAWindowPtr *previous = &dnWindow->fCAWindowList, caWindow;
- short index = 0, row;
-
- row = SearchCAList (dnWindow, caHand);
- if (row < 0)
- PutCLine (gLogWindow, kErrorColor, "### Can't find caHand (%08x) in caList", caHand);
- else {
- if (*previous) {
- while ((caWindow = *previous) && (index != row)) {
- ++index;
- previous = &caWindow->next;
- }
-
- if (index != row)
- PutCLine (gLogWindow, kErrorColor, "### Can't delete row %d because list has only %d rows", row, index);
- else {
- LDelRow (1, row, dnWindow->fCAList);
- *previous = caWindow->next;
- DisposeCAWindow (caWindow);
- }
- }
- }
- }
-
-
- DNWindowPtr GetDNWindow (TELCAHandle caHand)
- {
- DNWindowPtr dnWindow = nil;
-
- dnWindow = gTelWindow->fDNWindowList;
- while (dnWindow != nil) {
- if (dnWindow->fDNHandle == (*caHand)->hTELDN)
- break;
-
- dnWindow = dnWindow->next;
- }
-
- return (dnWindow);
- }
-
-
- short GetCAIndex (DNWindowPtr dnWindow, TELCAHandle caHand)
- {
- short row = 0;
- CAWindowPtr caWindow = dnWindow->fCAWindowList;
-
- while (caWindow) {
- if (caWindow->fCAHandle == caHand)
- break;
-
- caWindow = caWindow->next;
- ++row;
- }
-
- return (row);
- }
-
-
- void UpdateCAListState (DNWindowPtr dnWindow, TELCAHandle caHand)
- {
- short len, row;
- Str255 tString;
- char *stateStr;
- Cell tCell;
-
- if (dnWindow != nil) {
-
- (void) TELGetCAInfo (caHand);
-
- GetCAStateStr (caHand, &stateStr);
-
- len = sprintf ((char *) tString, "%08x %s (%d)", caHand, stateStr, (*caHand)->callType);
-
- if (len >= 0 ) {
- row = GetCAIndex (dnWindow, caHand);
- SetPt (&tCell, 0, row);
- LSetCell (tString, len, tCell, dnWindow->fCAList);
- }
- }
- else
- PutCLine (gLogWindow, kErrorColor, "### Can't find the corresponding dnWindow");
- }
-
-
- #pragma segment DNWindow
- TELCAHandle GetNthCA (short n, DNWindowPtr dnWindow)
- {
- CAWindowPtr caWindow = dnWindow->fCAWindowList;
- short index = 0;
- TELCAHandle caHand = nil;
-
- if (n)
- {
- while (caWindow) {
- if (++index == n)
- return (caWindow->fCAHandle);
-
- caWindow = caWindow->next;
- }
- }
-
- return (caHand);
- }
-
-
-